import { InputItem, SelectItem, DataRangeItem, SelectCorrItem, SaverConfigType, AsyncSelectItem } from './common-form-type';

import CNAddr from './AddrChina.json';

export const excempleInput: InputItem = {
  name: 'input',
  prop: 'username',
  label: '用户名',
  placeholder: '请输入用户名',
  defaultValue: '',
  span: 6,
  rules: [
    {
      required: true,
      message: '用户名是必填项！',
      trigger: 'blur',
    },
    {
      min: 3,
      max: 5,
      message: '用户名的长度应在3~5位！',
      trigger: 'blur',
    },
  ],
};

export const excempleSelect: SelectItem = {
  name: 'select',
  prop: 'sex',
  label: '性别',
  placeholder: '请选择性别',
  defaultValue: '',
  span: 6,
  options: () => [
    { label: '男', value: 1 },
    { label: '女', value: 0 },
  ],
  style: 'width:100%',
};

export const excempleAsyncSelect: AsyncSelectItem = {
  name: 'select',
  prop: 'sex',
  label: '性别',
  placeholder: '请选择性别',
  defaultValue: '',
  span: 6,
  url: '/',
};

export const excempleDataRange: DataRangeItem = {
  name: 'daterange',
  prop: 'times',
  label: '查询时间',
  span: 6,
  defaultValue: '',
  startPlaceholder: '开始时间',
  endPlaceholder: '结束时间',
  rangeSeparator: '至',
  style: 'width:100%',
};

export const excempleSelectSheng: SelectItem = {
  name: 'select',
  prop: 'sheng',
  label: '省',
  placeholder: '请选择省份',
  defaultValue: '',
  span: 6,
  options: () => CNAddr['000000'],
  style: 'width:100%',
};

export const excempleSelectShi: SelectCorrItem = {
  name: 'select-corr',
  prop: 'shi',
  corrProp: 'sheng',
  label: '市',
  placeholder: '请选择市',
  defaultValue: '',
  span: 6,
  options: (val: any) => (CNAddr as any)[val],
  style: 'width:100%',
};

export const excempleSelectXian: SelectCorrItem = {
  name: 'select-corr',
  prop: 'xian',
  corrProp: 'shi',
  label: '县',
  placeholder: '请选择县',
  defaultValue: '',
  span: 6,
  options: (val: any) => (CNAddr as any)[val],
  style: 'width:100%',
};

export const ExSaverConfig: SaverConfigType = {
  title: '新增用户',
  width: '480px',
  submitMethod: async (formData) => {
    console.log('弹框回调 :: ', JSON.stringify(formData));
    return true;
  },
};
